Kademlia DHT

您所在的位置:网站首页 libp2p python 源码解读 Kademlia DHT

Kademlia DHT

2024-07-14 22:28| 来源: 网络整理| 查看: 265

A deeper look

The routing table is organized based on a prefix length and a distance metric. The prefix length helps to group similar keys, and the distance metric helps to find the closest peers to a specific key in the routing table. The table maintains a list of k closest peers for each possible prefix length between 0 and L-1, where L is the length of the keyspace, determined by the length of the hash function used. Kad-DHT uses SHA-256, with a keyspace of 256 bits, trying to maintain k peers with a shared key prefix for every prefix length between 0 and 255 in its routing table.

The prefix length measures the proximity of two keys in the routing table and divides the keyspace into smaller subspaces, called “buckets”, each containing nodes that share a common prefix of bits in their SHA-256 hash. The prefix length is the number of bits that are the same in the two keys’ SHA-256 hash. The more leading bits that are the same, the longer the prefix length and the closer the proximity of the two keys are considered to be.

The distance metric is a way to calculate the distance between two keys by taking the bitwise exclusive-or (XOR) of the SHA-256 hash of the two keys. The result is a measure of the distance between the two keys, where a distance of 0 means the keys are identical, and a distance of 1 means that only one bit is different, meaning the two keys are close to each other (i.e. their SHA-256 hashes are similar).

This design allows for efficient and effective lookups in the routing table when trying to find nodes or data that share similar prefixes.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3